/**
 * Created by JERY on 2017/7/17.
 */
define(['jsTree','css!assets/jquery/jstree/themes/default/style.min.css'], function () {
    var ko = {};
    ko.jsTreeViewModel = function (options) {
        var self = this;
        self.defaults = {
            core: {
                data: {
                    data: function (node) {
                        return JSON.stringify({'nodeId': node.id});
                    },
                    contentType: 'application/json',
                    dataType: 'json',
                    method: 'post'
                },
                plugins: ['wholerow', 'types', 'search','checkbox'],
                types: {'default': {'icon': 'fa fa-folder'}, 'file': {'icon': 'fa fa-file-text-o'}}
            }
        };
        self.params = $.extend({}, self.defaults, options || {});

        self.getSelections = function () {
            return self.jstree(true).get_selected();
        };

        self.refresh = function (data) {//全量树刷新
            self.jstree(true).settings.core.data = data;
            self.jstree(true).refresh();
        }
    };
    return ko;
});
